﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using InvoiceChecking.Data;
using InvoiceChecking.Settings.BusinessLayer;

public partial class Admin_ReportReturn : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            tb_ReceiveDate.Text = DateTime.Now.ToString("dd-MMM-yyyy");
            btn_Refresh_Click(null, null);
        }

    }

    protected void btn_Refresh_Click(object sender, EventArgs e)
    {
        Invoices.TitleDataTable dsTitle = new Invoices.TitleDataTable();
        HttpCookie conCookie = Request.Cookies["ICConnectionString"];
        if (conCookie != null)
        {
            //ServiceFacade.SettingsHelper.ReturnInvoicesTitle = "THE DAILY RETURNED AND UNSUBMITTED INVOICES REPORT";
            dsTitle.AddTitleRow(ServiceFacade.SettingsHelper.ReturnInvoicesTitle, conCookie.Value);
            DataSet ds;
            SqlCommand cmd = new SqlCommand("ICReport_ReturnInvoices");
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("Date", DateTime.Parse(tb_ReceiveDate.Text)));
            cmd.Parameters.Add(new SqlParameter("Type", -1));
            if (cb_Return.Checked && !cb_Unsubmit.Checked)
                cmd.Parameters["Type"].Value = 1;
            else if (!cb_Return.Checked && cb_Unsubmit.Checked)
                cmd.Parameters["Type"].Value = 0;
            ds = DataRepository.Provider.ExecuteDataSet(cmd);
            ReportViewer1.LocalReport.DataSources["Invoices_Title"].Value = dsTitle;
            ReportViewer1.LocalReport.DataSources["Invoices_Return"].Value = ds.Tables[0];
            ReportViewer1.LocalReport.DataSources["Invoices_ReturnSum"].Value = ds.Tables[1];
            ReportViewer1.DataBind();
        }
    }
}

